package com.servlet.rootoperator;

import com.Impl.BookCRUD;
import com.entity.Book;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateBookServlet", value = "/UpdateBookServlet")
public class UpdateBookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String bookIdStr = request.getParameter("bookId");
        int bookId = Integer.parseInt(bookIdStr);
        String bookName = request.getParameter("bookName");
        String bookCategory = request.getParameter("bookCategory");
        String author = request.getParameter("author");
        String publisher = request.getParameter("publisher");
        String priceStr = request.getParameter("price");
        double price = Double.parseDouble(priceStr);
        Book book = new Book(bookId, bookName, bookCategory, author, publisher, price);
        BookCRUD bookCRUD = new BookCRUD();
        int i = bookCRUD.updateBook(book);
        System.out.println("影响了"+i+"行数据");



    }
}
